let app=getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    showEdit:false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getUnit();
    this.setData({
      domain:app.globalData.domain,
      width:app.globalData.windowWidth,
      height:app.globalData.windowHeight,
      statusBarHeight:app.globalData.statusBarHeight,
      navHeight:app.globalData.navHeight,
      marginTop:app.globalData.navTitleTop
    })
  },
  getUnit:function(){
    let that=this;
    var open=wx.getStorageSync('open');
    var member_id=open.member_id;
    wx.request({
      url: app.globalData.domain+'member/unit/getUnitList',
      data:{from:1, member_id: member_id},
      success:res=>{
        console.log(res.data);
        that.setData({
          list:res.data
        })
        console.log(that.data.list);
      }
    })
   
  },

  goBack:function(){
    wx.navigateBack();
  },
  editUnit:function(e){
    var id=e.currentTarget.dataset.id; 
    this.setData({
      showEdit:true,
      id:id
    })
  },
  inputValue:function(e){
    this.setData({
      value:e.detail.value
    })
  },
  findMember:function(){
    let that=this;
    var value=this.data.value;
    wx.request({
  
      url: app.globalData.domain+'member/member/getMember',
      data:{value:value},
      success:res=>{
        console.log(res.data);
        that.setData({
          member:res.data.member,
          status:res.data.status
        })
        
      }
    })
  },
  selectMember:function(e){
    

    var member_id=e.currentTarget.dataset.member_id;
    var name=e.currentTarget.dataset.name;
    var phone=e.currentTarget.dataset.phone;
    if(member_id==""){
      wx.showToast({
        title: '请选择用户',
      })
    }else{
      this.setData({
        member_id:member_id,
        name:name,
        phone:phone
      })
    }
  },
  cancleLeader:function(){
    this.setData({
      showEdit:false,
      id:0,
      member_id:'',
      name:'',
      phone:''
     })
    },
  setLeader:function(){
    let that=this;
    let data=this.data;
    if(data.member_id==""){
      wx.showToast({
        title: '请选择用户',
      })
    }else{
      wx.request({
        url: app.globalData.domain+'member/unit/setUnitLeader',
        data:{id:data.id,member_id:data.member_id,name:data.name,phone:data.phone},
        success:res=>{
         // console.log(res);
         wx.showToast({
           title: res.data.msg,
         })
         that.getUnit();
         that.setData({
          showEdit:false,
          id:0,
          member_id:'',
          name:'',
          phone:''
         })
        }
      })
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})